﻿/*
 * Copyright (c) 2010-2013 Ruben Chakhmakhchyan. All rights reserved.
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Eclipse Public License
 * Version 1.0 (the 'License'). You may not use this file except in
 * compliance with the License. Please obtain a copy of the License at
 * http://opensource.org/licenses/EPL-1.0 and read it before using this file.
 */

#pragma once

#include "commontypes.h"


class String
{
public:

    typedef void* (*Allocator)(size_t);
    typedef void (*Eraser)(void*);

public:

    static wchar_t* ToWchar( const char* string );
    static size_t ToWchar( wchar_t* dest, const char* string );

    static bool IsUtf8Ascii( const char* string );
    static bool IsUtf16Ascii( const wchar_t* string );

    static void Copy( char** dest, const char* source );

    static size_t GetLength( const char* value );
    static size_t GetLength( const wchar_t* value );

    static size_t ToUtf8( char** result, const wchar_t* value, size_t length, Allocator allocate, Eraser erase );
    static size_t ToUtf8( char** result, const wchar_t* value, size_t length );
    static size_t ToUtf8( char** result, const wchar_t* value, Allocator allocate, Eraser erase );
    static size_t ToUtf8( char** result, const wchar_t* value );

    static char* Clone( const char* value, Allocator allocate );
    static char* Clone( const char* value );

    static wchar_t* Utf8ToWideChar( const char* chars, size_t length );

    static bool Equal( const char* string1, const char* string2 );
    static bool Equal( const wchar_t* string1, const wchar_t* string2 );
};
